import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 登录页面
  {
    path: '/',
    redirect: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true,
    children: [
      {
        path: '/login'
      }
    ]
  },
  // 首页
  {
    path: '/dashboard',
    component: Layout,
    children: [{
      path: '',
      meta: { title: '工作台', icon: 'dashboard' },
      name: 'Dashboard',
      component: () => import('@/views/Dashboard/index')
    }
    ]
  },
  // 基础信息管理
  {
    path: '/manage-base-info',
    component: Layout,
    meta: { title: '基础信息管理', icon: 'base' },
    children: [{
      path: '',
      name: 'manage',
      component: () => import('@/views/Manage')
    },
    {
      path: 'warehouse',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '仓库管理' },
          name: 'warehouse',
          component: () => import('@/views/Manage/components/warehouse.vue')
        },
        {
          path: 'detile/:id',
          name: 'warehouse-detile',
          hidden: true,
          component: () => import('@/views/Manage/components/children/warehouse-details.vue'),
          meta: { title: '新建仓库' }
        }
      ]
    },
    {
      path: 'area',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '库区管理' },
          name: 'area',
          component: () => import('@/views/Manage/components/area.vue')
        },
        {
          path: 'detile/:id',
          name: 'area-details',
          hidden: true,
          component: () => import('@/views/Manage/components/children/area-details.vue'),
          meta: { title: '新增库区' }
        }
      ]
    },
    {
      path: 'location',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '库位管理' },
          name: 'location',
          component: () => import('@/views/Manage/components/location.vue')
        },
        {
          path: 'detile/:id',
          name: 'location-details',
          hidden: true,
          component: () => import('@/views/Manage/components/children/location-details.vue'),
          meta: { title: '新增库位' }
        }
      ]
    },
    {
      path: 'location-view',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '库位视图' },
          name: 'location-view',
          component: () => import('@/views/Manage/components/location-view.vue')
        }
      ]
    },
    {
      path: 'goods',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '货品管理' },
          name: 'goods',
          component: () => import('@/views/Manage/components/goods.vue')
        },
        {
          path: 'detile/:id',
          name: 'goods-details',
          hidden: true,
          component: () => import('@/views/Manage/components/children/goods-details.vue'),
          meta: { title: '新增货品' }
        }
      ]
    },
    {
      path: 'goods-type',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '货品类型管理' },
          name: 'goods-type',
          component: () => import('@/views/Manage/components/goods-type.vue')
        }
      ]
    }
    ]
  },
  // 商务管理
  {
    path: '/manage-business',
    component: Layout,
    meta: { title: '商务管理', icon: 'owner' },
    children: [{
      path: '',
      name: 'manage',
      component: () => import('@/views/Business/index.vue')
    },
    {
      path: 'goods-owner',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '货主管理' },
          name: 'goods-owner',
          component: () => import('@/views/Business/components/goods-owner.vue')
        },
        {
          path: 'detile/:id',
          name: 'goods-owner-detile',
          hidden: true,
          component: () => import('@/views/Business/components/children/goods-owner-details.vue'),
          meta: { title: '新建货主' }
        },
        {
          path: 'detile/:id',
          name: 'owner-detile',
          hidden: true,
          component: () => import('@/views/Business/components/children/owner-details.vue'),
          meta: { title: '货主详情' }
        }
      ]
    },
    {
      path: 'task-picking',
      component: { render(c) { return c('router-view') } },
      children: [
        {
          path: '',
          meta: { title: '承运商管理' },
          name: 'task-picking',
          component: () => import('@/views/Business/components/task-picking.vue')
        }]
    }
    ]
  }
  // // 库内管理
  // {
  //   path: '/manage-storage',
  //   component: Layout,
  //   meta: { title: '库内管理', icon: 'storege' },
  //   children: [{
  //     path: '',
  //     name: 'storage',
  //     component: () => import('@/views/Storage')
  //   },
  //   {
  //     path: 'list',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '盘点单' },
  //         name: 'list',
  //         component: () => import('@/views/Storage/components/warehouse.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'list-detile',
  //         hidden: true,
  //         component: () => import('@/views/Storage/components/children/list-details.vue'),
  //         meta: { title: '新建仓库' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'list-task',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '盘点任务' },
  //         name: 'list-task',
  //         component: () => import('@/views/Storage/components/list-task.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'list-task-details',
  //         hidden: true,
  //         component: () => import('@/views/Storage/components/children/list-task-details.vue'),
  //         meta: { title: '新增库区' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'storage-lose-profit',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '库存损益' },
  //         name: 'storage-lose-profit',
  //         component: () => import('@/views/Storage/components/storage-lose-profit.vue')
  //       }
  //     ]
  //   },
  //   {
  //     path: 'latest-storage',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '实时库存' },
  //         name: 'latest-storage',
  //         component: () => import('@/views/Storage/components/latest-storage.vue')
  //       }
  //     ]
  //   }
  //   ]
  // },
  // // 入库管理
  // {
  //   path: '/manage-storage-in',
  //   component: Layout,
  //   meta: { title: '入库管理', icon: 'storageIn' },
  //   children: [{
  //     path: '',
  //     name: 'storageIn',
  //     component: () => import('@/views/In')
  //   },
  //   {
  //     path: 'list-in/list',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '入库单' },
  //         name: 'list-in',
  //         component: () => import('@/views/In/components/list-in.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'list-in-detile',
  //         hidden: true,
  //         component: () => import('@/views/In/components/children/list-in-details.vue'),
  //         meta: { title: '新建仓库' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'list-in/task-receive',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '收货任务' },
  //         name: 'task-receive',
  //         component: () => import('@/views/In/components/task-receive.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'task-receive-details',
  //         hidden: true,
  //         component: () => import('@/views/In/components/children/task-receive-details.vue'),
  //         meta: { title: '新增库区' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'list-in/task-add',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '上架任务' },
  //         name: 'task-add',
  //         component: () => import('@/views/In/components/task-add.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'task-add-details',
  //         hidden: true,
  //         component: () => import('@/views/In/components/children/task-add-details.vue'),
  //         meta: { title: '新增库位' }
  //       }
  //     ]
  //   }
  //   ]
  // },
  // // 出库管理
  // {
  //   path: '/manage-storage-out',
  //   component: Layout,
  //   meta: { title: '入库管理', icon: 'storageOut' },
  //   children: [{
  //     path: '',
  //     name: 'storageOut',
  //     component: () => import('@/views/Out')
  //   },
  //   {
  //     path: 'list-out',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '出库单' },
  //         name: 'list-out',
  //         component: () => import('@/views/Out/components/list-out.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'list-out-detile',
  //         hidden: true,
  //         component: () => import('@/views/Out/components/children/list-out-details.vue'),
  //         meta: { title: '新建仓库' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'task-picking',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '拣货任务' },
  //         name: 'task-picking',
  //         component: () => import('@/views/Out/components/task-picking.vue')
  //       },
  //       {
  //         path: 'detile/:id',
  //         name: 'task-picking-details',
  //         hidden: true,
  //         component: () => import('@/views/Out/components/children/task-picking-details.vue'),
  //         meta: { title: '新增库区' }
  //       }
  //     ]
  //   },
  //   {
  //     path: 'manage-task-transfer',
  //     component: { render(c) { return c('router-view') } },
  //     children: [
  //       {
  //         path: '',
  //         meta: { title: '交接任务' },
  //         name: 'manage-task-transfer',
  //         component: () => import('@/views/Out/components/manage-task-transfer.vue')
  //       }
  //     ]
  //   }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// reset 路由方法
export function resetRouter() {
  // 得到一个全新的 router 实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher // reset router
}
export default router
